<template>
	<view style="position: relative;border: 1px solid #d9d9d9; padding-left: 20rpx;">
		<image :src="item" mode="aspectFit" v-if="imgUrl" style="width:800upx;height:200upx;margin-right:30upx;" @click="TanPreviewImage(item)"></image>
		<u-icon name="close-circle" @tap="delect(index)" class='img_icon' v-show="imgUrlS"></u-icon>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				imgUrl: [],
			};
		},
		props: ['item', 'index', 'imgUrlS'],
		methods: {
			TanPreviewImage(imageUrl) {
				//console.log(imageUrl) // http://192.168.100.251:8970/6_1597822634094.png
				var images = [];
				images.push(imageUrl);
				//console.log(images) // ["http://192.168.100.251:8970/6_1597822634094.png"]
				uni.previewImage({ // 预览图片  图片路径必须是一个数组 => ["http://192.168.100.251:8970/6_1597822634094.png"]
					current: 0,
					urls: images,
					// longPressActions: { //长按保存图片到相册
					// 	itemList: ['保存图片'],
					// 	success: (data) => {
					// 		//console.log(data);
					// 		uni.saveImageToPhotosAlbum({ //保存图片到相册
					// 			filePath: payUrl,
					// 			success: function() {
					// 				uni.showToast({
					// 					icon: 'success',
					// 					title: '保存成功'
					// 				})
					// 			},
					// 			fail: (err) => {
					// 				uni.showToast({
					// 					icon: 'none',
					// 					title: '保存失败，请重新尝试'
					// 				})
					// 			}
					// 		});
					// 	},
					// 	fail: (err) => {
					// 		//console.log(err.errMsg);
					// 	}
					// }
				});
			},
			delect(index) {
				var that = this;
				function removeByValue(arr, val) {
					for (var i = 0; i < arr.length; i++) {
						if (arr[i] == val) {
							arr.splice(i,1)
							break;
						}
					}
				}
				var forImg = that.imgUrlS[index];
				//var imageUrl = that.imgUrlS.splice(forImg, 1)
				removeByValue(that.imgUrlS, forImg);
				// uni.showModal({
				// 	title: '提示',
				// 	content: '是否删除该图片？',
				// 	success: (res) => {
				// 		if (res.confirm) {
				// 			//删除数组中指定项
				// 			function removeByValue(arr, val) {
				// 				for (var i = 0; i < arr.length; i++) {
				// 					if (arr[i] == val) {
				// 						arr.splice(i, 1);
				// 						break;
				// 					}
				// 				}
				// 			}
				// 			//console.log(that.imgUrlS)
				// 			var forImg = that.imgUrlS[index];
				// 			var imageUrl = that.imgUrlS.splice(forImg, 1)
				// 			removeByValue(that.imgUrlS, imageUrl);
				// 			//重新赋值
				// 			//that.imgAllUrl = that.imageList
				// 		}
				// 	}
				// });
			}
		}
	}
</script>

<style lang="less">
	image {
		width: 145rpx !important;
		margin: 0rpx;
	}

	.img_icon {
		position: absolute;
		    right: 0px;
		    color: rgb(154, 154, 154);
		    top: 0px;
		    font-size: 22px;
	}
</style>
